package com.three.controller;

import com.three.aop.LogAnotation;
import com.three.entity.Branch;
import com.three.service.BranchService;
import com.three.vo.AddBranchVo;
import com.three.vo.BranchVo;
import com.three.vo.DzDiaoLiVo;
import com.three.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/branch")
public class BranchController {
    @Autowired
    private BranchService branchService;
    //查询所有分店名称
    ////查询所有门店
    @GetMapping("/list")
    @LogAnotation("查询所有门店不包含小张店")
    public R list(){
        return branchService.selectAll();
    }
    @GetMapping("/getBranchName")
    @LogAnotation("查询所有门店名称")
    public R getBranchName()
    {
        return branchService.getBranchName();
    }

    @GetMapping("/getBranchName02")
    public R getBranchName02()
    {
        return branchService.getBranchName02();
    }

    //查询所有商铺信息和根据店长id查询店长名称
    @PostMapping("/getAllAndName")
    public R getBranchInfo(Integer currentPage, Integer pageSize,@RequestBody BranchVo branchname)
    {
        //System.out.println(branchname);
        return branchService.getAllAndName(currentPage, pageSize,branchname);
    }
    //添加商铺
    @PostMapping("/addBranch")
    @LogAnotation("添加商铺")
    public R addBranch(@RequestBody AddBranchVo addBranch)
    {
        return branchService.addBranch(addBranch);
    }
    //判断商铺编号是否重复
    @GetMapping("/checkBranchid")
    public R checkBranchid(Integer branchid)
    {
        return branchService.checkBranchid(branchid);
    }
    //checkBranchname判断门店名称是否重复
    @GetMapping("/checkBranchname")
    public R checkBranchname(String branchname)
    {
        return branchService.checkBranchname(branchname);
    }
    //根据商铺id查询商铺信息
    @GetMapping("/getBranchByBranchId")
    public R getBranchByBranchId(Integer branchid)
    {
        return branchService.getBranchByBranchId(branchid);
    }
    //修改商铺信息
    @PostMapping("/updateBranch")
    @LogAnotation("修改商铺信息")
    public R updateBranch(@RequestBody Branch branch)
    {
        return branchService.updateBranch(branch);
    }
    //修改门店状态
    @GetMapping("/updateState")
    @LogAnotation("修改门店状态")
    public R updateBranchState(Integer branchid,Integer state)
    {
        //System.out.println(branchid+" "+state);
        return branchService.updateState(branchid,state);
    }
    //删除方法
    @GetMapping("/deleteBranch")
    @LogAnotation("删除门店")
    public R deleteBranch(Integer branchid) {
        return branchService.deleteBranch(branchid);
    }
    //更换店长操作
    @GetMapping("/updatedianzhang")
    @LogAnotation("更换店长操作")
    public R updatedianzhang(Integer branchid,Integer staffid)
    {
        //System.out.println(branchid+" "+staffid);
        //return null;
         return branchService.updateDianZhang(branchid,staffid);
    }

    @GetMapping("/getUserBranchName")
    //根据当前登录用户的id查询该用户的门店名称
    public R getUserBranchName()
    {
        return branchService.getUserBranchName();
    }

    @GetMapping("/getUserBranchid")
    //根据当前登录用户的id查询该用户的门店id
    public R getUserBranchid()
    {
        return branchService.getUserBranchId();
    }

    //店长调离方法
    @PostMapping("dianzhangdiaoli")
    @LogAnotation("店长调离")
    public R dianZhangDiaoLi(@RequestBody DzDiaoLiVo dzDiaoLiVo){
        //System.out.println(dzDiaoLiVo);
        //return null;
        return branchService.dianZhangDiaoLi(dzDiaoLiVo);
    }
    //得到当前登陆人的门店
    @GetMapping("/getNewBranch")
    public R getNewBranch()
    {
        return branchService.getNewBranch();
    }

}
